import {
    CREATE_COMMENTS_SUCCESS,
    FETCH_COMMENTS_SUCCESS
} from '../actions'

export default function (state = { resources: {}}, action){
    switch(action.type) {
        case FETCH_COMMENTS_SUCCESS:
        case CREATE_COMMENTS_SUCCESS:
            if (action.response.length === 0) {
                return state;
            }
            return {
                ...state,
                resources: {
                    ...state.resources,
                    [action.response[0].article_uuid]: action.response
                }
            }
        default:
            return state
    }
}
